package pe.edu.upc.dew.grupo5.web;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.support.WebApplicationContextUtils;

import pe.edu.upc.dew.grupo5.model.Cliente;
import pe.edu.upc.dew.grupo5.service.ClienteService;

/**
 * Servlet implementation class DatosClienteServlet
 */
public class DatosClienteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private ClienteService clienteService;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DatosClienteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	public void init(ServletConfig config) throws ServletException {
		this.clienteService = WebApplicationContextUtils
		.getWebApplicationContext(config.getServletContext()).getBean(
				"clienteService", ClienteService.class);
	}
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Cliente cliente = new Cliente();
		try{
			cliente = clienteService.getClientePorMail((String) session.getAttribute("usuario"));
			request.setAttribute("cliente", cliente);
			request.getRequestDispatcher("cuenta.jsp").forward(request,response);
		}  catch (Exception e) {
			System.out.println("error: " + e);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
